﻿using System;
using System.ComponentModel;
using System.Reflection;

namespace EnumTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string result = GetEnumDes();
        }

        /// <summary>
        /// 返回指定枚举值的描述信息 
        /// </summary>
        /// <param name="enumValue"></param>
        /// <returns></returns>
        public static string GetEnumDes(Enum enumValue)
        {
            string value = enumValue.ToString();
            FieldInfo field = enumValue.GetType().GetField(value);
            object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
            if (objs == null || objs.Length == 0)
                return value;
            DescriptionAttribute descriptionAttribute = (DescriptionAttribute)objs[0];
            return descriptionAttribute.Description;
        }
    }

    /// <summary> 
    /// 七色机印刷颜色枚举 
    /// </summary>
    public enum EnumSevenColor
    {
        /// <summary>
        /// 青
        /// </summary>
        [Description("青")]
        Cyan = 0,
        /// <summary>
        /// 品
        /// </summary>
        [Description("品")]
        Magenta = 1,
        /// <summary>
        /// 黄
        /// </summary>
        [Description("黄")]
        Yellow = 2,
        /// <summary>
        /// 黑
        /// </summary>
        [Description("黑")]
        Black = 3,
        /// <summary>
        /// 白
        /// </summary>
        [Description("白")]
        White = 4,
        /// <summary>
        /// 紫
        /// </summary>
        [Description("紫")]
        Violet = 5,
        /// <summary>
        /// 橙
        /// </summary>
        [Description("橙")]
        Orange = 6,
    }
}
